package com.ruoyi.yuce.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yuce.domain.Fengjifaultcode;
import com.ruoyi.yuce.service.IFengjifaultcodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风机错误代码Controller
 *
 * @author xinhui
 * @date 2023-01-17
 */
@RestController
@RequestMapping("/ruoyi-yuce/fengjifaultcode")
@DataSource(value = DataSourceType.SLAVE)
public class FengjifaultcodeController extends BaseController
{
    @Autowired
    private IFengjifaultcodeService fengjifaultcodeService;

    /**
     * 查询风机错误代码列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:fengjifaultcode:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fengjifaultcode fengjifaultcode)
    {
        startPage();
        List<Fengjifaultcode> list = fengjifaultcodeService.selectFengjifaultcodeList(fengjifaultcode);
        return getDataTable(list);
    }

    /**
     * 导出风机错误代码列表
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:fengjifaultcode:export')")
    @Log(title = "风机错误代码", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fengjifaultcode fengjifaultcode)
    {
        List<Fengjifaultcode> list = fengjifaultcodeService.selectFengjifaultcodeList(fengjifaultcode);
        ExcelUtil<Fengjifaultcode> util = new ExcelUtil<Fengjifaultcode>(Fengjifaultcode.class);
        util.exportExcel(response, list, "风机错误代码数据");
    }

    /**
     * 获取风机错误代码详细信息
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:fengjifaultcode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(fengjifaultcodeService.selectFengjifaultcodeById(id));
    }

    /**
     * 新增风机错误代码
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:fengjifaultcode:add')")
    @Log(title = "风机错误代码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fengjifaultcode fengjifaultcode)
    {
        return toAjax(fengjifaultcodeService.insertFengjifaultcode(fengjifaultcode));
    }

    /**
     * 修改风机错误代码
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:fengjifaultcode:edit')")
    @Log(title = "风机错误代码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fengjifaultcode fengjifaultcode)
    {
        return toAjax(fengjifaultcodeService.updateFengjifaultcode(fengjifaultcode));
    }

    /**
     * 删除风机错误代码
     */
    @PreAuthorize("@ss.hasPermi('ruoyi-yuce:fengjifaultcode:remove')")
    @Log(title = "风机错误代码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(fengjifaultcodeService.deleteFengjifaultcodeByIds(ids));
    }
}
